<?php

namespace App\Http\Controllers;

use App\Week2M;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class Week2C extends Controller
{

    /**
     * 注册
     */
    public function Adds( Request $request )
    {
        $this->validate($request, [
            'name' => 'required|unique:week2|max:255',
            'pwd' => 'required',
            'email' => 'required',
            'tel' => 'required',
            'Address' => 'required',
            'photos' => 'required',
        ]);

        $res = Week2M::Adds($request);
        if ($res) {
            // $person = "$name.在.$date('Y'.年.'m'.月.'d'.日  'H:i:s',time()).'进行了注册的操作/n'";
            // file_put_contents($res, $person, FILE_APPEND | LOCK_EX);
        
            return redirect('week-list');
        } else {
            return redirect('week-add');
        }
    }

/**
 * 地图
 */
    public static function Maps( Request $request )
    {

        $Address = $request['Address'];
        $arr = file_get_contents("http://api.map.baidu.com/geocoding/v3/?address=$Address&output=json&ak=LNeMoilfSRgFVdR9WBa03Z9HxABewtTU");
        $data = json_decode($arr,true);
        $lng = $data['result']['location']['lng'];
        $lat = $data['result']['location']['lat'];

        return ['lng'=>$lng,'lat'=>$lat];
    }
/**
 * 
 * 邮件
 */

    public function Emails( Request $request )
    {
        $email = $request['email'];
        $message = '由于技能时间过长，录屏中时刻检查好自己的录屏信息，避免出现摄像头卡顿、电脑黑屏等现象！考试是为了检测当周所学程度，找到自己的问题，切勿作弊！作弊可耻！';
        $to = '495938288@qq.com';
        $subject = '全栈开发学院[考试管理项目组]';
       Mail::send(
       'email.Emails', 
       ['content' => $message], 
       function ($message) use($to, $subject) { 
           $message->to($to)->subject($subject); 
       });
    }













    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Week2M  $week2M
     * @return \Illuminate\Http\Response
     */
    public function show(Week2M $week2M)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Week2M  $week2M
     * @return \Illuminate\Http\Response
     */
    public function edit(Week2M $week2M)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Week2M  $week2M
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Week2M $week2M)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Week2M  $week2M
     * @return \Illuminate\Http\Response
     */
    public function destroy(Week2M $week2M)
    {
        //
    }
}
